package com.ruoyi.basic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basic.domain.MaterialCategory;
import com.ruoyi.basic.service.IMaterialCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料类别Controller
 * 
 * @author ruoyi
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/basic/materialCategory")
public class MaterialCategoryController extends BaseController
{
    @Autowired
    private IMaterialCategoryService materialCategoryService;

    /**
     * 查询物料类别列表
     */
    @PreAuthorize("@ss.hasPermi('basic:materialCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialCategory materialCategory)
    {
        startPage();
        List<MaterialCategory> list = materialCategoryService.selectMaterialCategoryList(materialCategory);
        return getDataTable(list);
    }

    /**
     * 导出物料类别列表
     */
    @PreAuthorize("@ss.hasPermi('basic:materialCategory:export')")
    @Log(title = "物料类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialCategory materialCategory)
    {
        List<MaterialCategory> list = materialCategoryService.selectMaterialCategoryList(materialCategory);
        ExcelUtil<MaterialCategory> util = new ExcelUtil<MaterialCategory>(MaterialCategory.class);
        util.exportExcel(response, list, "物料类别数据");
    }

    /**
     * 获取物料类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:materialCategory:query')")
    @GetMapping(value = "/{macId}")
    public AjaxResult getInfo(@PathVariable("macId") Long macId)
    {
        return success(materialCategoryService.selectMaterialCategoryByMacId(macId));
    }

    /**
     * 新增物料类别
     */
    @PreAuthorize("@ss.hasPermi('basic:materialCategory:add')")
    @Log(title = "物料类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialCategory materialCategory)
    {
        return toAjax(materialCategoryService.insertMaterialCategory(materialCategory));
    }

    /**
     * 修改物料类别
     */
    @PreAuthorize("@ss.hasPermi('basic:materialCategory:edit')")
    @Log(title = "物料类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialCategory materialCategory)
    {
        return toAjax(materialCategoryService.updateMaterialCategory(materialCategory));
    }

    /**
     * 删除物料类别
     */
    @PreAuthorize("@ss.hasPermi('basic:materialCategory:remove')")
    @Log(title = "物料类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{macIds}")
    public AjaxResult remove(@PathVariable Long[] macIds)
    {
        return toAjax(materialCategoryService.deleteMaterialCategoryByMacIds(macIds));
    }
}
